<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use ValiDate;
use App\Facades\Services\RecoveryService;

class RecoveryController extends Controller
{
    public function addRecovery(Request $request){
    	$rules = [
    		'type_id' => 'required|exists:recovery_types,id',
    		'volumn' => 'required',
    		'weight' => 'required',
    		'photos' => 'required|array',
    		'address' => 'required'
    	];

    	ValiDate::valiDate($request,$rules);

    	$data = $request->all();

    	// dd(json_decode(json_encode($data['photos'])));

    	RecoveryService::addRecovery($data);

    	return formatJsonResponse();
    }

    public function getRecoveryByStatus(Request $request){
    	$rules = [
    		'status' => 'required'
    	];

    	ValiDate::valiDate($request,$rules);

    	$data = $request->all();

    	return formatJsonResponse(RecoveryService::getRecoveryByStatus($data));
    }

    public function getRecoveries(Request $request){
    	return formatJsonResponse(RecoveryService::getRecoveries());
    }

    public function getRecoveryTypes(Request $request){
    	return formatJsonResponse(RecoveryService::getRecoveryTypes());
    }

    public function updateRecovery(Request $request){
    	$rules = [
    		'id' => 'required|exists:recoveries,id',
    		'type_id' => 'required|exists:recovery_types,id',
    		'volumn' => 'required',
    		'weight' => 'required',
    		'photos' => 'required|array',
    		'address' => 'required'
    	];

    	ValiDate::valiDate($request,$rules);

    	$data = $request->all();

    	return formatJsonResponse(RecoveryService::updateRecovery($data));

    }
}
